import * as types from './mutation-types'
import axios from 'axios'

const actions = {
  //   onUserLogin: (commit, data) => {
  //     //axios 
  //     console.log(data.username);
  //     console.log(data.upwd);

  //     // axios get user info  save to state

  //     // commit(types.USERLOGIN,userinfo);
  //   },

  onUserLogin({
    commit
  }, userInfo) {
    console.log(userInfo);

    return new Promise((resolve, reject) => {

      axios.post('/api/user/logoin', userInfo).then(response => {
        const data = response.data
        console.log(data);
        commit(types.USERLOGIN, data.userinfo);
        resolve(data)
      }).catch(error => {
        reject(error)
      })



    })
  },

};

export default actions;
